import { Button } from 'antd';
import { connect } from 'dva';
import { RouteComponentProps } from 'dva/router';
import React from 'react';
import { IconFont } from '../../../config/IconConfig';
import { IGlobal } from '../../../Model/GlobalModel';
import UpdateTitle from '../../../utils/UpdateTitle';
import Foot from './../../../components/Foot/Foot';
import './SubmitCase.scss';
interface IProps
  extends RouteComponentProps<{
    code: string;
    name: string;
    sampleSequence: string;
  }> {
  global: IGlobal;
}
class SubmitCase extends React.Component<IProps, {}> {
  public componentDidMount(): void {
    UpdateTitle(this.props.global.companyInfo.name ? this.props.global.companyInfo.name : '');
  }

  public render() {
    const urlStr: string = this.getQueryVariable('roleAndUrl') || '';
    return (
      <div className="SubmitCase">
        <div className="topArea">
          <div className="header2">病例名称：{this.props.match.params.name}</div>
        </div>
        <div className="contetArea">
          <div className="contentContainer">
            <IconFont className="fontSize" type="iconicon_finish1" />
            <div className="submit"> 提交成功</div>
            <div className="codeTitle"> 您的就诊序号</div>
            <div className="codeNum">{this.props.match.params.sampleSequence}</div>
            <div className="hintTitle"> 请找医生获得预约单后再关闭该页面</div>
            {// tslint:disable-next-line:jsx-no-multiline-js
            urlStr && urlStr !== 'undefined' ? (
              <div>
                <Button type={'primary'} onClick={() => this.props.history.push('/' + urlStr.replace(/,/g, '/'))}>
                  返回通知列表
                </Button>
              </div>
            ) : null}
          </div>
        </div>
        <Foot logoUrl={this.props.global.companyInfo.logoUrl} name={this.props.global.companyInfo.name} />
      </div>
    );
  }
  /**
   * 获取 url 参数
   */
  private getQueryVariable = (urlKey: string) => {
    const url = window.location.href;
    const reg = /[?&][^?&]+=[^?&]+/g;
    const arr = url.match(reg);
    const obj = new Map();
    if (arr) {
      arr.forEach(item => {
        const tempArr = item.substring(1).split('=');
        const key = decodeURIComponent(tempArr[0]);
        const val = decodeURIComponent(tempArr[1]);
        obj.set(key, val);
      });
    }
    return obj.get(urlKey);
  };
}

export default connect((global: IGlobal) => global)(SubmitCase);
